// Source File Name:   Exceptions.java

package com.vhly.classfile;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

// Referenced classes of package com.vhly.classfile:
//            Attribute, Debug

public class Exceptions
        implements Attribute {

    private int exs[];
    private int ex_count;
    private int name_index;
    private int data_len;

    public Exceptions() {
        name_index = 0;
        data_len = 0;
        ex_count = 0;
        exs = null;
    }

    public void setNameIndex(int i) {
        name_index = i;
    }

    public int getNameIndex() {
        return name_index;
    }

    public void setDataLen(int i) {
        data_len = i;
    }

    public int getDataLen() {
        return data_len;
    }

    public void read(DataInputStream datainputstream, boolean flag)
            throws IOException {
        if (flag)
            name_index = datainputstream.readUnsignedShort();
        data_len = datainputstream.readInt();
        ex_count = datainputstream.readUnsignedShort();
        exs = new int[ex_count];
        for (int i = 0; i < ex_count; i++)
            exs[i] = datainputstream.readUnsignedShort();

    }

    public void write(DataOutputStream dataoutputstream)
            throws IOException {
        if (Debug.isEnabled())
            System.out.println("    Write Exceptions Attribute");
        dataoutputstream.writeShort(name_index);
        if (Debug.isEnabled())
            System.out.println((new StringBuilder()).append("    Write Exceptions Attribute Name Index:0x").append(Integer.toHexString(name_index)).toString());
        dataoutputstream.writeInt(data_len);
        if (Debug.isEnabled())
            System.out.println((new StringBuilder()).append("    Write Exceptions Attribute DataLen:0x").append(Integer.toHexString(data_len)).toString());
        dataoutputstream.writeShort(ex_count);
        if (Debug.isEnabled())
            System.out.println((new StringBuilder()).append("    Write Exceptions Attribute Exception Count:0x").append(Integer.toHexString(ex_count)).toString());
        for (int i = 0; i < exs.length; i++) {
            dataoutputstream.writeShort(exs[i]);
            if (Debug.isEnabled())
                System.out.println((new StringBuilder()).append("    Write Exceptions Attribute Exception:0x").append(Integer.toHexString(exs[i])).toString());
        }

    }

    public int getType() {
        return 8;
    }
}